/**
 * 私有、辅助方法，显示完成按钮的结果
 * @param info
 */
function audioEditShowPostInfo(info) {
    var parent = $('#post-fiction-result');
    info = '<li>' + info + '</li>';
    parent.append(info);
}

function audioEditOnButtonClearClick() {
    $('#audio-broadcaster').val('');
    $('#audio-platform').val('');
}

/**
 * 按下页面上的完成按钮会呼叫的方法
 */
function audioEditOnButtonFinishClick() {
    var reader = $('#audio-broadcaster').val();
    var source = $('#audio-platform').val();
    var cid = $('#current-fiction-handle').attr('value');

    $.ajax(
        {
            type: 'post',
            async: true,
            data: {
                'cid': cid,
                'reader': reader,
                'source': source
            },
            url: document.location.origin + '/api/addaudio',
            dataType:'text',
            success: function(data) {
                var json = JSON.parse(data);

                if (json.result == 200) {
                    audioEditShowPostInfo(reader + " | " + source + " 添加成功");
                }
                else {
                    audioEditShowPostInfo(reader + " | " + source + " 出错：" + json.description);
                }
            },
            error: function () {
                console.log("Ajax 发生错误！");
            }
        }
    );

}

$(document).ready(function() {
    $("#audio-table-handle").DataTable({
        "paging": false,         //是否分页，如果是false，则全部显示，否则默认是10个数据一页
        "lengthChange": false,   //是否可以控制每页多少个数据，这个会影响Show x entries的显示
        "searching": false,      //是否要显示search栏
        "ordering": false,       //是否出排序的小控件
        "info": false,           //表格的左下方是否需要显示Showing # to # of # entries
        "autoWidth": true,       //
        "language": {
            "lengthMenu": "每页显示记录 _MENU_",
            "zeroRecords": "没有任何内容",
            "info": "当前第_PAGE_页，共_PAGES_页",
            "infoEmpty": "No records available",
            "infoFiltered": "(filtered from _MAX_ total records)",
            "search": "搜索：",
            "paginate": {
                "first":      "首頁",
                "last":       "末頁",
                "next":       "下一頁",
                "previous":   "前一頁"
            },
        },

    });
});